//
//  LspNbTextButton.swift
//  LspSwiftFinayTest
//
//  Created by lsp's mac pro on 2018/5/2.
//  Copyright © 2018年 lsp's mac pro. All rights reserved.
//

import UIKit

class LspNbTextButton: UIButton {

    init(title:String?){
        super.init(frame: CGRect())
        if title == nil {
            setTitle("首页", for: [])
        }else{
            setTitle(title! + " ", for: [])
            setImage(UIImage.init(named: "navigationbar_arrow_down"), for: [])
            setImage(UIImage.init(named: "navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray, for: [])
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {

        super.layoutSubviews()

        guard let titleLabel = titleLabel,let imageView = imageView else {
            return
        }
//修改button 图片和文字的调整方式 左右 上下 居中等
      self.titleEdgeInsets = UIEdgeInsets(top: 0.0, left: -imageView.frame.size.width - self.frame.size.width + titleLabel.intrinsicContentSize.width, bottom: 0.0, right: 0.0)
        
      self.imageEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: -titleLabel.frame.size.width - self.frame.size.width + imageView.frame.size.width)


    }

    
}
